package cn.jtfadmin.base.lang.config.statuscode;


import cn.jtfadmin.base.lang.config.WebConfig;
import org.apache.commons.lang3.exception.ExceptionUtils;

import java.util.*;

/**
 * 异常返回值状态码配置
 *
 * @author jtf
 * @see StatusCodeConfig
 * @see StatusCodeManager
 * @see WebConfig#configureHandlerExceptionResolvers(List)
 * @since 0.0.1
 */
public interface ExceptionStatusCodeConfig extends StatusCodeConfig {


    /**
     * 获取异常的异常栈cause
     * @param t 异常
     * @return
     */
     static   List<Throwable> getCause(Throwable t){
        List<Throwable> list = new ArrayList<>();
        list.add(t);
        Throwable cause = t.getCause();
        while (cause !=null){
            list.add(cause);
            cause = cause.getCause();
        }
        Collections.reverse(list);
        return list;
    }



    @Override
    default Set<StatusDescribe> getStatusDecribes() {
        Set<StatusDescribe> set = new HashSet<>();
        for (ExceptionStatusDescribe exStatusDecribe : getExStatusDecribes()) {
            set.add(exStatusDecribe);
        }
        return set;
    }

    /**
     * 获取状态描述
     *
     * @return 获取状态描述
     */
    Set<ExceptionStatusDescribe> getExStatusDecribes();
}
